<template>
	<view class="pages-box rel" v-if="isLoad">
		<view class="pd-lg f-paragraph">
			<parser :html="configInfo.cancellation_agreement" @linkpress="linkpress" show-with-animation lazy-load>加载中...
			</parser>
		</view>
		<view class="space-max-footer"></view>
				
		<fix-bottom-button @confirm="loginOut" borderRadius="8rpx" :text="[{text:'我已阅读并理解，仍要注销',type:'confirm',isAuth:false}]" bgColor="#fff">
		</fix-bottom-button>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import siteInfo from '@/siteinfo.js';
	import parser from "@/components/jyf-Parser/index"
	export default {
		components: {
			parser
		}, 
		data() {
			return {
				isLoad: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			coachInfo: state => state.user.coachInfo,
		}),
		async onLoad(options) {
			this.$util.showLoading()
			this.initIndex()
		},
		methods: {
			...mapActions(['getConfigInfo', 'getCoachInfo']),
			...mapMutations(['updateConfigItem', 'updateUserItem']),
			async initIndex(refresh = false){
				if(!this.configInfo.id || refresh){
					await this.getConfigInfo()
				}
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				if(!this.coachInfo.id || refresh){
					await this.getCoachInfo()
				}
				this.$util.hideAll()
				this.isLoad = true
			},
			linkpress(res) {
				// #ifdef APP-PLUS
				this.$util.goUrl({
					url: res.href,
					openType: 'web'
				})
				// #endif
			},
			async loginOut(){
				if(this.coachInfo.cash > 0){
					let [res_del, {
						confirm
					}] = await uni.showModal({
						content: `账户资金未提现，是否注销`,
					})
					if (!confirm) return;
				}
				
				await this.$api.user.logout()
				this.updateUserItem({
					key: 'isAppLogin',
					val: false
				})
				this.updateUserItem({
					key: 'userInfo',
					val: {}
				})
				this.updateUserItem({
					key: 'coachInfo',
					val: {}
				})
				
				this.updateUserItem({
					key: 'autograph',
					val: ''
				})
				this.$util.showToast({
					title: '注销成功'
				})
				setTimeout(()=>{
					this.$util.goUrl({url: '/login/pages/index', openType: 'reLaunch'})
				},1000)
			}
		},
	}
</script>


<style lang="scss">
	page{
		background: #fff;
	}
	.pages-box {
		.use-box{
			margin: 20rpx 25rpx;
		}
		.out-btn{
			margin: 20rpx 25rpx 0 25rpx;
		}
	}
</style>
